package com.jt.pojo.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.Data;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;


@Component//将对象交给spring容器管理
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Date date=new Date();

        this.setFieldValByName( "created" ,date,metaObject);
        this.setFieldValByName(  "updated",date,metaObject);
    }
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(  "updated" , new Date(),metaObject);
    }
}
